/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.ui
{
	import com.competentum.lib.events.CommandEvent;
	
	import flash.ui.Keyboard;

	public class Shortcut
	{
		public var keyCode:int;
		public var ctrl:Boolean;
		public var alt:Boolean;
		public var shift:Boolean;
		public var events:Array;
		[Bindable]
		public var title:String;
		
		public function Shortcut(title:String, events:Array, keyCode:int, ctrl:Boolean = true, alt:Boolean = false, shift:Boolean = false)
		{
			this.title = title;
			this.events = events;
			this.keyCode = keyCode;
			this.ctrl = ctrl;
			this.alt = alt;
			this.shift = shift;
		}
		
		public function asText():String
		{
			var result:String = '';
			result += (ctrl) ? 'Ctrl+' : '';
			result += (alt) ? 'Alt+' : '';
			result += (shift) ? 'Shift+' : '';
			result += String.fromCharCode(keyCode);
			return result;
		}
		
		public function asXML():XML
		{
			var result:XML = new XML('<shortcut></shortcut>');
			result.@title = title;
			result.@keyCode = keyCode;
			result.@ctrl = ctrl;
			result.@alt = alt;
			result.@shift = shift;
			return result;
		}
	}
}